home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Interactive 7
/
PC World Interactive 7.iso
/
program
/
ctutord.EXE
/
STRUC1.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-16
|
674b
|
36 lines
/* struc1.c */
struct T1 { int cnt; char t[20]; };
struct T2 { char *s; int i; struct T1 at; };
main()
{
int i=1;
static struct T2 a[] = {
"abcd", 100, { 99, "hi" },
"efgh", 101, { 100, "hi there" },
"xyz", 102, { 101, "see ya" }
};
struct T2 abc, *p;
p = &a[i++];
printf("%s\n",p->at.t);
printf("%s\n",p->s);
printf("%d\n",p->i);
i=replace(&abc, &a[--i]);
printf("%s\n",abc.s);
printf("%d\n",i);
}
replace(p1,p2)
struct T2 *p1, *p2;
{
int i;
for(i=0; p2->at.t[i] != 0; i++)
p1->at.t[i] = p2->at.t[i];
p1->at.t[i] = p2->at.t[i];
p1->s = p2->s;
p1->i = p2->i;
p1->at.cnt = p1->i + p2->i;
return(p1->at.cnt);
}